﻿using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF_SocketServer_Demo.Base;
using WPF_SocketServer_Demo.Interface;
using WPF_SocketServer_Demo.RequestInfo;
using WPF_SocketServer_Demo.Server;
using WPF_SocketServer_Demo.Session;

namespace WPF_SocketServer_Demo.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly IDataReader _dataReader;

        public MainWindow()
        {
            InitializeComponent();
            _dataReader = new DataReaderBase();
            _dataReader.MessageObservable.Subscribe(message =>
            {
                Dispatcher.Invoke(() => LogTextBox.AppendText($"{message}\n"));
            });
        }

        private void StartServer_Click(object sender, RoutedEventArgs e)
        {
            if (_dataReader.Init())
            {
                LogTextBox.AppendText("Server started.\n");
            }
            else
            {
                LogTextBox.AppendText("Failed to start server.\n");
            }
        }

        private void StopServer_Click(object sender, RoutedEventArgs e)
        {
            _dataReader.Close();
        }
    }
}
